import random
import datetime
from uuid import uuid4

from blog.models import db, User, Tag, Post

user = User(id=str(uuid4()), username='test', password='test')
db.session.add(user)
db.session.commit()

user = db.session.query(User).first()
tag_one = Tag(id=str(uuid4()), name='Python')
tag_two = Tag(id=str(uuid4()), name='Java')
tag_three = Tag(id=str(uuid4()), name='C++')
tag_four = Tag(id=str(uuid4()), name='Php')
tag_list = [tag_one, tag_two, tag_three, tag_four]

s = "肩负历史重任，面对现实考验，人民军队如何不辱使命、续写辉煌？习主席站在时代发展和战略全局高度运筹帷幄、深远经略，" \
    "亲自领导制定新形势下军事战略方针，为全军练兵备战立起了总纲；鲜明确立战斗力这个唯一的根本的标准，" \
    "为全军练兵备战标绘了清晰坐标；反复强调要从实战需要出发，从难从严训练部队，为全军练兵备战指明了路径；果断把握历史机遇，" \
    "深化国防和军队改革，为全军练兵备战注入了新的动力。 "

for i in range(100):
    new_post = Post(id=str(uuid4()), title="聚力胜战再出发" + str(i))
    new_post.user = user
    new_post.publish_date = datetime.datetime.now()
    new_post.text = s
    new_post.tags = random.sample(tag_list, random.randint(1, 3))
    db.session.add(new_post)

db.session.commit()
